﻿using TPA.DataAccess;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using LinqToExcel;
using System.Collections.Generic;

namespace TPA.Test
{
    
    
    /// <summary>
    ///This is a test class for ProgramReaderTest and is intended
    ///to contain all ProgramReaderTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ProgramReaderTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for AllTVPrograms
        ///</summary>
        [TestMethod()]
        public void AllTVProgramsTest()
        {
            ProgramLogReader target = new ProgramLogReader(); // TODO: Initialize to an appropriate value
            string excelfilename = @"D:\Projects\TV Program Analyst\Names.xls"; // TODO: Initialize to an appropriate value
            string firstname ="John"; // TODO: Initialize to an appropriate value
            List<Row> actual;
            actual = target.GetProgramLog(excelfilename,"节目");
            Assert.AreEqual(3, actual.Count);
            Assert.AreEqual(firstname, actual[2][0].Value.ToString());
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for ConvertStartDateTime
        ///</summary>
        [TestMethod()]
        [DeploymentItem("TPA.DataAccess.dll")]
        public void ConvertStartDateTimeTest_Normal()
        {
            ProgramLogReader_Accessor target = new ProgramLogReader_Accessor(); // TODO: Initialize to an appropriate value
            string date = "2011/11/15"; // TODO: Initialize to an appropriate value
            string time = "2:26:26"; // TODO: Initialize to an appropriate value
            DateTime expected = DateTime.Parse(date+" "+time); // TODO: Initialize to an appropriate value
            DateTime actual;
            actual = target.ConvertToDateTime(date, time);
            Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for ConvertStartDateTime
        ///</summary>
        [TestMethod()]
        [DeploymentItem("TPA.DataAccess.dll")]
        public void ConvertStartDateTimeTest_HourBiggerThan24()
        {
            ProgramLogReader_Accessor target = new ProgramLogReader_Accessor(); // TODO: Initialize to an appropriate value
            string date = "2011/11/15"; // TODO: Initialize to an appropriate value
            string time = "24:26:26"; // TODO: Initialize to an appropriate value
            DateTime expected = DateTime.Parse("2011/11/16 0:26:26"); // TODO: Initialize to an appropriate value
            DateTime actual;
            actual = target.ConvertToDateTime(date, time);
            Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for ConvertStartDateTime
        ///</summary>
        [TestMethod()]
        [DeploymentItem("TPA.DataAccess.dll")]
        public void ConvertStartDateTimeTest_DateTimeString_Normal()
        {
            ProgramLogReader_Accessor target = new ProgramLogReader_Accessor(); // TODO: Initialize to an appropriate value
            string date = "2011/11/15"; // TODO: Initialize to an appropriate value
            string time = "1899/12/30 2:26:26AM"; // TODO: Initialize to an appropriate value
            DateTime expected = DateTime.Parse("2011/11/15 2:26:26"); // TODO: Initialize to an appropriate value
            DateTime actual;
            actual = target.ConvertToDateTime(date, time);
            Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for ConvertStartDateTime
        ///</summary>
        [TestMethod()]
        [DeploymentItem("TPA.DataAccess.dll")]
        public void ConvertStartDateTimeTest_DateTimeString_HourBiggerThan24()
        {
            ProgramLogReader_Accessor target = new ProgramLogReader_Accessor(); // TODO: Initialize to an appropriate value
            string date = "2011/11/15"; // TODO: Initialize to an appropriate value
            string time = "1900/1/1 0:26:26 AM"; // TODO: Initialize to an appropriate value
            DateTime expected = DateTime.Parse("2011/11/16 0:26:26"); // TODO: Initialize to an appropriate value
            DateTime actual;
            actual = target.ConvertToDateTime(date, time);
            Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

    }
}
